<template>
  <div class="modifyPwd">
    <x-header title="" :left-options="{backText:'密码设置'}" class='whiteHeader'></x-header>
    <div class="pwdInfo">
    	<div class="pwdInfo1">
    		<input type="text" placeholder="请输入旧密码" v-model="oldPwd"/>
    	</div>
    	<div class="pwdInfo2">
    		<input type="password" placeholder="请输入新密码,密码长度6-16" v-model="newPwd"/>
    	</div>
    	<div class="pwdInfo3">
    		<input type="password" placeholder="请再次输入密码" v-model="newPwdEnsure"/>
    	</div>    	
    </div>
    <div class="modifyEnsure" @click="updatePwd">
    	<button>确定</button>
    </div>
    <div class="modifyBlank"></div>
  </div>
</template>
<script>
/*密码设置*/
import {XHeader,Alert} from 'vux';
import { setCookie, getCookie } from '../../util/commonUtils';
export default {
  name:"modifyPwd",
  // 数据
  data(){

    return{
    	userId:'',
    	oldPwd:'',//旧密码
    	newPwd:'',//新密码
    	newPwdEnsure:'',//新密码确认
    }
  },
  // 计算属性
  computed:{

  },
  // 创建（实例创建完成）
  created(){
    this.userId=getCookie('loginkey');
    //this.userId = 169623;
  },
  // el被创建，并挂载到实例上
  mounted(){

  },
  // 方法（实例中的方法）-----------
  methods:{  		
    	//修改密码
    	updatePwd(){    		
  			if(this.oldPwd==''||this.oldPwd==null){  				
  				this.$vux.alert.show({title:'提示',content:'旧密码不能为空!'});return;
  			}
  			if(this.newPwd==''||this.newPwd==null){  				
  				this.$vux.alert.show({title:'提示',content:'新密码不能为空!'});return;
  			}  		
  			if(this.newPwdEnsure==''||this.newPwdEnsure==null){  				
  				this.$vux.alert.show({title:'提示',content:'密码不能为空!'});return;
  			}
  			if(!(this.newPwd.length >= 6 && this.newPwd.length <= 16)){  				
  				this.$vux.alert.show({title:'提示',content:'密码长度不正确!'});return;
  			}
  			if(this.newPwd != this.newPwdEnsure){  				
  				this.$vux.alert.show({title:'提示',content:'两次密码不一致!'});return;
  			}
  			//修改密码 文档是1.0版本
  			let obj = {};
  			obj.USER_ID = this.userId;
  			obj.OLD_PASSWORD = this.oldPwd;
  			obj.NEW_PASSWORD = this.newPwd;
		    this.$fetchPost('/CUser/UpdateUserPwd',obj).then(res=>{    			    		
		            if(res.STATUS_CODE == 1){		            		
		            		this.$vux.alert.show({title:'提示',content:'密码修改成功!'});
		            		this.$router.go(-1);
		            }else if(res.STATUS_CODE == 2){		            		
		            		this.$vux.alert.show({title:'提示',content:'旧密码不正确!'});return;
		            }
		    },err=>console.log(err));
    	},
  },
  // 子组件
  components:{
    XHeader,
    Alert,
  }
}
</script>
<!--当前页面的样式 -->
<style lang="less" scoped>
.modifyPwd{
  	background:#ededed;
  	.pwdInfo{
  		margin-top:0.5rem;
  		height:2.64rem;  		 	
  		.pwdInfo1{
  			border-top:0.01rem solid #aaaaaa;   
  		}
  		.pwdInfo1,.pwdInfo2,.pwdInfo3{
  			width:100%;
  			height:0.88rem;  			
  			border-bottom:0.01rem solid #aaaaaa;  
  			background: #fff;  	  	  					
  			input{
  				border:none;
  				width:7.5rem;
  				height:0.74rem;  	  										
  				border-radius:0;  
  				display: block;
  				line-height:0.74rem;	
  				outline:medium;		
  				text-indent:0.3rem;  								
  			}
  			input:focus{
			    text-indent:0.3rem;
			}			
  			input::placeholder {
  				display:block;
  				text-align:left;
  				width:7.5rem;
  				height:0.88rem;
  				font-size:0.28rem;
  				color:#c9c9cf;  				
  				text-indent:0.3rem;    				
  						
		    }		    
  		}  		
  	}
  	.modifyEnsure{
  		width:100%;
  		height:0.88rem;
  		background:#ededed;
  		margin-top:0.26rem;
  		display:flex;
  		justify-content:center;
  		button{
  			border:none;
  			border-radius:0.1rem;
  			width:6.72rem;
  			height:100%;
  			background:#ec383f;
  			font-size:0.28rem;
  			color:#fff;
  			font-weight:bold;
  		}
  	}
  	.modifyBlank{
  		height:9.25rem;
  		background:#ededed;
  	}
}
</style>